/**
 * GenericComponentsService.java
 *
 * Copyright (c) 2010 Prj.Manager All Rights Reserved.
 *
 * This source file may not be copied, modified or redistributed,
 * in whole or in part, in any form or for any reason, without the express
 * written consent of Prj.Manager .
 **/
package ro.prjmanager.service;



import ro.prjmanager.core.service.AbstractService;
import ro.prjmanager.core.service.Service;
import ro.prjmanager.dao.GenericComponentsDao;
import ro.prjmanager.model.GenericComponents;

import java.util.List;

/**
 * This class is business logic for generic_components table
 * It manages all transaction maded to generic_components table
 * @author Viorel Tacliciu
 * @version 1
 **/


public class GenericComponentsService  extends AbstractService<GenericComponents,Integer> implements Service<GenericComponents,Integer> {




    public GenericComponentsDao getDao() {
        return (GenericComponentsDao) dao;
    }



    public void delete(Integer id){
        GenericComponents delObj =new GenericComponents();
        delObj.setId(id);
        dao.delete(delObj);
    }

    public GenericComponents load(Integer id){
         return dao.find(id,false);
    }

    public List<GenericComponents> listPag(int startPage,int resPerPage){
          return dao.listPag(startPage, resPerPage);
    }

    public List<GenericComponents> listPagFilter(int startPage,int resPerPage,String filter){
          return dao.listPagFilter(startPage, resPerPage, filter);
    }

    public int no(String filter) {
        return dao.no(filter);
    }

    public void update( GenericComponents entity) {
        GenericComponents genericComponentsDb=dao.find(entity.getId(),false);

        if(entity.getDescription()!=null)
            genericComponentsDb.setDescription(entity.getDescription());
        if(entity.getName()!=null)
            genericComponentsDb.setName(entity.getName());
        if(entity.getFkFixedComponents()!=null)
            genericComponentsDb.setFkFixedComponents(entity.getFkFixedComponents());
        if(entity.getFkProjectLayer()!=null)
            genericComponentsDb.setFkProjectLayer(entity.getFkProjectLayer());
        if(entity.getFkTemplate()!=null)
            genericComponentsDb.setFkTemplate(entity.getFkTemplate());
        if(entity.getRelativePackage()!=null)
            genericComponentsDb.setRelativePackage(entity.getRelativePackage());
        if(entity.getSuffix()!=null)
            genericComponentsDb.setSuffix(entity.getSuffix());
        genericComponentsDb.setRes(entity.isRes());
        genericComponentsDb.setWeb(entity.isWeb());

        dao.update(genericComponentsDb);
    }

    public List<GenericComponents> listPag(int startPage, int resPerPage, String orderCol, boolean asc, Object... otherItems) {
        return getDao().listPag(startPage, resPerPage,orderCol,asc, otherItems);
    }

    public List<GenericComponents> list() {
        return getDao().list();
    }

}
